package com.crm.jdy.controller.client;

import com.crm.jdy.common.dto.CallAplanInfoDto;
import com.crm.jdy.common.dto.ClientSourceInfoDto;
import com.crm.jdy.common.pojo.CallAplanInfo;
import com.crm.jdy.common.pojo.ClientSourceInfo;
import com.crm.jdy.common.utils.api.ResultVo;
import com.crm.jdy.common.utils.currentlimiting.RateLimit;
import com.crm.jdy.service.client.CallAplanInfoService;
import com.crm.jdy.service.client.ClientSourceInfoService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
*
* <p>说明： 客户商机信息API接口层</P>
* @version: V1.0
* @author: kong
* @time    2021年1月26日
*
*/
@Validated
@Api(tags = "clientSourceInfo", description = "客户商机信息")
@RestController
@RequestMapping("/clientSourceInfo")
public class ClientSourceInfoController{

    @Reference(version = "${service.version}", check = false)
    ClientSourceInfoService callAplanInfoService;

    @RateLimit()
    @ApiOperation("商机信息")
    @PostMapping("/seleteClientSourceInfo")
    public ResultVo seleteClientSourceInfo(@RequestBody ClientSourceInfoDto clientSourceInfoDto){
        PageInfo<ClientSourceInfo> list = callAplanInfoService.seleteClientSourceInfo(clientSourceInfoDto);
        return  ResultVo.success(list);
    }

    @RateLimit()
    @ApiOperation("更新商机信息")
    @PostMapping("/updateClientSourceInfo")
    public ResultVo updateClientSourceInfo(@ApiParam(value = "clientSourceInfo", required = true)
                                           @Validated @RequestBody ClientSourceInfo clientSourceInfo){
        boolean index = callAplanInfoService.updateClientSourceInfo(clientSourceInfo);
        if(index){
            return  ResultVo.success();
        }
        return  ResultVo.failed();
    }

    @RateLimit()
    @ApiOperation("添加商机信息")
    @PostMapping("/addClientSourceInfo")
    public ResultVo addClientSourceInfo(@ApiParam(name = "clientSourceInfo", required = false)
                                        @Validated @RequestBody ClientSourceInfo clientSourceInfo){
        boolean list  = callAplanInfoService.addClientSourceInfo(clientSourceInfo);
        return  ResultVo.success(list);
    }

    @RateLimit()
    @ApiOperation("删除商机信息")
    @DeleteMapping("deleteClientSourceInfo/{srcId}")
    public ResultVo deleteClientSourceInfo(@NotNull @ApiParam(name = "srcId", value = "srcId ", required = true) @PathVariable String srcId){
        boolean b = callAplanInfoService.removeClientSourceInfo(srcId);
        if(b){
            return ResultVo.success();
        }
        return ResultVo.failed();
    }


}